import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { ShopService } from './shop.service';
import { CreateShopDto } from './dto/create-shop.dto';
import { UpdateShopDto } from './dto/update-shop.dto';
import { PageQuery } from '../../../util/entity/page.entity';
import { Shop } from './entities/shop.entity';
import { ReqUser } from '../../../common/decorator/user.decorator';

@Controller()
export class ShopController {
  constructor(private readonly shopService: ShopService) {}

  @Post()
  create(@Body() createShopDto: CreateShopDto) {
    return this.shopService.create(createShopDto);
  }

  @Post('buy/:id')
  buy(@Param('id') id: number, @ReqUser('id') userId: number) {
    return this.shopService.buy(id, userId);
  }

  @Post('list')
  findAll(@Body() pageQuery: PageQuery<Shop>) {
    return this.shopService.findAll(pageQuery);
  }

  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.shopService.findOne(id);
  }

  @Patch(':id')
  update(@Param('id') id: number, @Body() updateShopDto: UpdateShopDto) {
    return this.shopService.update(id, updateShopDto);
  }

  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.shopService.remove(id);
  }
}
